package com.group2.demo_country_group2;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CountryAdapter extends BaseAdapter{

	private int resID;
	private Context context;
	private List<MyCountry> countries;
	
	public CountryAdapter(Context context, int resID, List<MyCountry> countries) {
	
		// TODO Auto-generated constructor stub
		this.context = context;
		this.resID = resID;
		this.countries = countries;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		
		if(convertView != null){
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(resID, null);
			
			holder = new ViewHolder();
			
			holder.tvNameEn = (TextView) convertView.findViewById(R.id.tvNameEn);
			holder.tvNameVi = (TextView) convertView.findViewById(R.id.tvNameVi);
			holder.ivFlag = (ImageView) convertView.findViewById(R.id.ivFlag);
			
			convertView.setTag(holder);
		}else
			holder = (ViewHolder) convertView.getTag();
		holder.tvNameEn.setText(countries.get(position).getNameEn());
		holder.tvNameVi.setText(countries.get(position).getNameVi());
		byte[] image = countries.get(position).getImage();
		Bitmap bitmap = BitmapFactory.decodeByteArray(image, 0, image.length);
		holder.ivFlag.setImageBitmap(bitmap);
		return null;
	}
	class ViewHolder{
		TextView tvNameEn;
		TextView tvNameVi;
		ImageView ivFlag;
		
	}

}
